import cv2
import  numpy as np
if __name__ == '__main__':
    path = 'work6.jpg'
    image_np = cv2.imread(path)
    image_np_hsv = cv2.cvtColor(image_np, cv2.COLOR_BGR2HSV)

    low = (0, 43, 46)
    high = (180, 255, 255)
    # g_low = ()
    # g_high = ()
    # b_low = ()
    # b_high = ()
    # y_low = ()
    # y_high = ()
    mask = cv2.inRange(image_np_hsv, low, high)
    kernel1 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
    kernel2 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))
    mask_kernel1 = cv2.erode(mask, kernel1)
    mask_kernel2 = cv2.dilate(mask_kernel1, kernel2)
    mask_kernel3 = cv2.bitwise_not(mask_kernel2)
    image_np0 = cv2.cvtColor(mask_kernel3, cv2.COLOR_GRAY2BGR)
    # print(image_np0)
    # cv2.imshow('', mask_kernel3)
    image_np1 = cv2.bitwise_or(image_np, image_np0)         # 或运算如果参与掩膜，会自动变成与运算
    cv2.imshow('', image_np1)
    cv2.waitKey(0)
    cv2.imwrite('zuoye6.jpg', image_np1)